import { Ast } from "../ast";
import { BaseVisitor } from "../core";
import { RedPacketInfo, RedPacketInfoVisitor } from "./RedPacketInfoVisitor";
export function getLiveRoomRedPackets(node: Ast) {
    const ctx: { list?: RedPacketInfo[], close?: () => void } = { list: [] }
    const visitor = new LiveRoomRedPacketsVisitor();
    visitor.visitNode(node, ctx)
    if (ctx && ctx.list.length > 0) {
        return ctx;
    }
}
export class LiveRoomRedPacketsVisitor extends BaseVisitor<{ list?: RedPacketInfo[], close?: () => void }> {
    visitImageView(node: Ast, ctx: { list?: RedPacketInfo[], close?: () => void }) {
        if (node.sid === `live_red_packet_container_close_view`) {
            ctx.close = () => node.click()
            return;
        }
        if (node.id.endsWith(`close_view`)) {
            ctx.close = () => node.click()
            return;
        }
    }
    visitViewPager(node: Ast, ctx: { list?: RedPacketInfo[], close?: () => void }) {
        if (node.id.endsWith(`live_red_packet_container_view_pager`)) {
            // 获取红包信息
            const visitor = new RedPacketInfoVisitor()
            const redPackets = node.children.map(child => {
                const redPacket = {}
                visitor.visitNode(child, redPacket)
                return redPacket;
            })
            ctx.list.push(...redPackets)
            return;
        }
        node.children.map(child => child.visit(this, ctx))
    }
}